package com.eastfair.venueservice.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
//import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eastfair.boot.service.SuperServiceImpl;
import com.eastfair.constant.BusinessConstant;
import com.eastfair.core.base.R;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.venueservice.dao.ServiceProviderCreditMapper;
import com.eastfair.venueservice.dto.ServiceProviderCreditDTO;
import com.eastfair.venueservice.entity.ServiceProviderCredit;
import com.eastfair.venueservice.service.ServiceProviderCreditService;
import com.eastfair.venueservice.vo.ServiceProviderCreditVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.Objects;

/**
 * <p>
 * 业务实现类
 * 服务商信用表
 * </p>
 *
 * @author lyw
 * @date 2022-08-11
 */
@Deprecated
@Slf4j
@Service
//@DS("#thread.tenant")
public class ServiceProviderCreditServiceImpl extends SuperServiceImpl<ServiceProviderCreditMapper, ServiceProviderCredit> implements ServiceProviderCreditService {

    /**
     * 处理逻辑删除相关处理
     *
     * @param modelList 实体
     * @return 是否成功
     */
    @Override
    protected R<Boolean> handlerRemoveByIdsOfLogic(Collection<ServiceProviderCredit> modelList) {
        modelList.forEach(s -> s.setIsDeleted(BusinessConstant.YES));
        return R.successDef();
    }

    @Override
    protected R<Boolean> handlerSave(ServiceProviderCredit model) {
        model.setProjectId(ContextUtil.getProjectId());
        model.setSubsystemId(ContextUtil.getSubSystemId());
        return R.successDef();
    }

    @Override
    public ServiceProviderCreditVO getServiceProviderCreditVOById(Long serviceProviderId) {
        log.info("getServiceProviderCreditById - 查询服务商星级分, params={}", serviceProviderId);
        // 查询展厅列表
        QueryWrapper<ServiceProviderCredit> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(ServiceProviderCredit::getIsDeleted, BusinessConstant.DELETE_NO)
                .eq(Objects.nonNull(serviceProviderId), ServiceProviderCredit::getServiceProviderId, serviceProviderId);
        ServiceProviderCredit serviceProviderCredit = this.getOne(queryWrapper);
        return BeanUtil.toBean(serviceProviderCredit, ServiceProviderCreditVO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveServiceProviderCredit(ServiceProviderCreditDTO serviceProviderCreditDTO) {
        log.info("saveServiceProviderCreditInfo - 添加服务商信用星级分, params={}", JSONObject.toJSON(serviceProviderCreditDTO));
        ServiceProviderCredit serviceProviderCredit = BeanUtil.toBean(serviceProviderCreditDTO, ServiceProviderCredit.class);
        return this.save(serviceProviderCredit);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateServiceProviderCredit(ServiceProviderCreditDTO serviceProviderCreditDTO) {
        log.info("updateServiceProviderCreditInfo - 修改服务商信用星级分, params={}", JSONObject.toJSON(serviceProviderCreditDTO));
        ServiceProviderCredit serviceProviderCredit = BeanUtil.toBean(serviceProviderCreditDTO, ServiceProviderCredit.class);
        return this.updateById(serviceProviderCredit);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateCreditScore(ServiceProviderCreditDTO serviceProviderCreditDTO) {
        log.info("updateCreditScore - 更新服务商信用分值, serviceProviderCreditDTO={}", serviceProviderCreditDTO);

        return false;
    }

}
